<layout name="master"/>
<script src="__PUBLIC__/js/jquery.min.js"></script>
<ul class="breadcrumb no-border no-radius b-b b-light pull-in">
    <li><a href="index.html"><i class="fa fa-home"></i> Home</a></li>
    <li><a href="#">货品管理</a></li>
    <li class="active">货品列表</li>
</ul>
<div class="col-sm-12">
    <section class="panel panel-default">
        <header class="panel-heading font-bold">货品列表</header>
        <div class="panel-body">
            <form action="" method="post">
            <table class="table table-hover">
                <tr>
                    <th>货品id</th>
                    <volist name="specList" id="sl">
                        <th>{$sl['taname']}</th>
                    </volist>
                    <th>货号</th>
                    <th>库存</th>
                    <th>操作</th>
                </tr>
                <volist name="old" id="o">
                <tr>
                    <td>{$o['glid']}</td>
                    <volist name="o.spec" id="os">

                    <td>{$os}</td>
                    </volist>

                    <td>{$o['glnumber']}</td>
                    <td>{$o['inventory']}</td>
                    <td><a href="" class="btn btn-danger btn-xs">删除</a></td>
                </tr>
                </volist>
                <tr>
                    <td>添加货品</td>
                    <volist name="specList" id="sl">
                        <td>
                            <select name="combine[]" id="">
                                <option value="0">请选择</option>
                                <volist name="sl.select" id="sls">
                                    <option value="{$sls['gtid']}">{$sls['gtvalue']}</option>
                                </volist>
                            </select>
                        </td>
                    </volist>
                    <td><input type="text" name="glnumber" ></td>
                    <td><input type="text" name="inventory" ></td>
                    <td>
                        <input type="hidden" name="gid" value="{:I('get.gid')}">
                        <button type="submit" class="btn btn-success btn-xs">添加</button>
                    </td>
                </tr>

            </table>
            </form>
        </div>
    </section>
</div>
</div>
<script>
    function controller($scope,$){}

    var specNum = parseInt("<?php echo $specNum;?>");
    $('[name="combine[]"]').change(function(){
        var specArr = [];
        $('[name="combine[]"]').each(function(k,v){
            if($(v).val()!=0){
                specArr.push($(v).val());
            }
        })
        if(specArr.length==specNum){
            var combine = specArr.join(',');
            $.post("{:u('admin/goodsList/ajaxCheck')}",{combine:combine},function(data){
                if(data){
                    alert('货品已存在');
                    $('[name="combine[]"]').val(0);
                }
            });
        }
    })

</script>
